import request from '@/utils/request'


export function add(data) {

  return request({
    url: '/contract/add',
    method: 'post',
    data: data
  })
}
export function addkunbang(data) {

  return request({
    url: '/contract/addkunbang',
    method: 'post',
    data: data
  })
}

// 增加回款
export function addReturnValue(data) {

  return request({
    url: '/contract/addReturnValue',
    method: 'post',
    data: data
  })
}
// 修改登记
export function update(data) {

  return request({
    url: '/contract/update',
    method: 'post',
    data: data
  })
}

// 查询
export function Clientlist(){
  console.log("查询后台")
  return request({
    url: '/contract/clientlist',
    method: 'get',
  })
}

// 查询
export function queryMoth(query){

  return request({
    url: '/contract/queryMoth',
    method: 'get',
    params: query
  })
}

// 合同编号模糊查询
export function queryContractNumberByLike(queryString) {
  return request({
    url: '/contract/queryContractNumberByLike',
    method: 'get',
    params: { queryString }
  })
}

// 查询
export function queryReturnValue(query){
  console.log("查询回款")
  console.log(query)
  return request({
    url: '/contract/queryReturnValue',
    method: 'get',
    params: query
  })
}

// 查询
export function list(query){

  return request({
    url: '/contract/list',
    method: 'get',
    params: query
  })
}


// 修改定时任务调度
export function updateContract(data) {
  return request({
    url: '/contract/job',
    method: 'put',
    data: data
  })
}

export function queryInvoiceList(contractCode) {
  return request({
    url: '/contract/queryInvoiceList',
    method: 'get',
    params: { contractCode }
  })
}

// 删除定时任务调度
export function delContract(contractCode) {
  return request({
    url: '/contract/' + contractCode,
    method: 'delete'
  })
}

// 任务状态修改
export function changeJobStatus(jobId, status) {
  const data = {
    jobId,
    status
  }
  return request({
    url: '/monitor/job/changeStatus',
    method: 'put',
    data: data
  })
}


// 定时任务立即执行一次
export function runJob(jobId, jobGroup) {
  const data = {
    jobId,
    jobGroup
  }
  return request({
    url: '/monitor/job/run',
    method: 'put',
    data: data
  })}


export  function generateMonths(startDate, monthCount) {
  // 将传入的字符串格式日期转换为 Date 对象
  const start = new Date(startDate);

  // 初始化月份数组
  const months = [];

  // 生成未来的月份
  for (let i = 1; i <= monthCount; i++) {
      const futureDate = new Date(start);
      futureDate.setMonth(start.getMonth() + i); // 向后推算月份

      // 格式化生成字符串，输出 "YYYY-M月" 格式
      const year = futureDate.getFullYear();
      const month = futureDate.getMonth() + 1; // getMonth() 返回的是 0-11，所以加1
      months.push(`${year}-${month}月`);
  }

  return months;
}
